#  tests/test.c dependencies/catch2/catch2.cpp
INCLUDES = -I./dependencies/catch2 -I./src/vehicles -I./src/environment -I./dependencies/linkedlist
INCLUDES += -I./src/track -I./src/components -I./src/includes

COMPILER = g++

# 生成可执行文件:
build/test_main: build/catch.o build/test_sim.o
	$(COMPILER) $(INCLUDES) -o world.out build/catch2.o build/test_sim.o

# 编译 hello.c:
build/catch.o: dependencies/catch2/catch2.cpp
	$(COMPILER) $(INCLUDES) -c dependencies/catch2/catch2.cpp -o build/catch2.o

# 编译 main.c:
build/test_sim.o: tests/test_sim.cpp
	$(COMPILER) $(INCLUDES) -c tests/test_sim.cpp -o build/test_sim.o

LINKEDLIST_SRCS= 
LINKEDLIST_SRCS+=dependencies/linkedlist/list.c
LINKEDLIST_SRCS+=dependencies/linkedlist/list_node.c
LINKEDLIST_SRCS+=dependencies/linkedlist/list_iterator.c
LINKEDLIST_OBJECTS= $(patsubst %.c,%.o,${LINKEDLIST_SRCS})

${LINKEDLIST_OBJECTS}:%.o : %.c
	$(COMPILER) -c $< -o $@

linkedlist: ${LINKEDLIST_OBJECTS}

LOGIC_SRCS=
# LOGIC_SRCS+=src/vehicles/locomotives.c
# LOGIC_SRCS+=src/vehicles/railroad_car.c

# LOGIC_SRCS+=src/environment/environment.c
# LOGIC_SRCS+=src/components/electric_motor.c
LOGIC_OBJECTS= $(patsubst %.c,%.o,${LOGIC_SRCS})

${LOGIC_OBJECTS}:%.o : %.c
	$(COMPILER) $(INCLUDES) -c $< -o $@

# 编译CPP相关的文件
CPP_SRCS=
CPP_SRCS+=src/environment/environment.cpp
CPP_SRCS+=src/environment/tech_spec_lib.cpp
CPP_SRCS+=src/environment/railroad_operators.cpp
CPP_SRCS+=src/components/electric_motor.cpp
CPP_SRCS+=src/vehicles/locomotives.cpp
CPP_SRCS+=src/vehicles/railroad_car.cpp
CPP_SRCS+=src/track/track.cpp
CPP_SRCS+=src/track/route.cpp
CPP_SRCS+=src/vehicles/train.cpp
CPP_OBJECTS= $(patsubst %.cpp,%.o,${CPP_SRCS})
${CPP_OBJECTS}: %.o : %.cpp
	$(COMPILER) $(INCLUDES) -c $< -o $@

test_electric_motor: ${CPP_OBJECTS}
	$(COMPILER) $(INCLUDES) -g -c -o tests/test_electric_motor.o tests/test_electric_motor.cpp
	$(COMPILER) $(INCLUDES) -g tests/test_electric_motor.o ${CPP_OBJECTS} -o build/test_electric_motor -lm
	./build/test_electric_motor

test_vehicles: ${CPP_OBJECTS}
	$(COMPILER) $(INCLUDES) -g -c -o tests/test_vehicles.o tests/test_vehicles.cpp
	$(COMPILER) $(INCLUDES) -g tests/test_vehicles.o ${CPP_OBJECTS} -o build/test_vehicles -lm
	./build/test_vehicles

test_train_run: ${CPP_OBJECTS}
	$(COMPILER) $(INCLUDES) -g -c -o tests/test_train_run.o tests/test_train_run.cpp
	$(COMPILER) $(INCLUDES) -g tests/test_train_run.o ${CPP_OBJECTS} -o build/test_train_run -lm
	./build/test_train_run

build_test_track: ${LINKEDLIST_OBJECTS} ${LOGIC_OBJECTS}
	$(COMPILER) $(INCLUDES) -g -c -o tests/test_track.o tests/test_track.c
	$(COMPILER) $(INCLUDES) -g tests/test_track.o ${LOGIC_OBJECTS} ${LINKEDLIST_OBJECTS} -o build/test_track -lm


build_test_world:	${LINKEDLIST_OBJECTS} ${LOGIC_OBJECTS} ${CPP_OBJECTS}
	$(COMPILER) $(INCLUDES) -g -c -o tests/test_world.o tests/test_world.cpp
	$(COMPILER) $(INCLUDES) -g tests/test_world.o ${LOGIC_OBJECTS} ${LINKEDLIST_OBJECTS} ${CPP_OBJECTS} -o build/test_world -lm

test_track: build_test_track
	./build/test_track

test_world: build_test_world
	./build/test_world

shared: ${LINKEDLIST_OBJECTS} ${LOGIC_OBJECTS}
	$(COMPILER) ${LOGIC_OBJECTS} ${LINKEDLIST_OBJECTS} -o python_app/railsim/lib/core.dll -shared -lm

clean:
	rm ${LOGIC_OBJECTS} ${LINKEDLIST_OBJECTS} ${CPP_OBJECTS}
	rm tests/*.o

win_clean:
	del /S *.o

esbmc_verify:
	esbmc ./tests/test_sim2.c ${LINKEDLIST_SRCS} -I ./dependencies/linkedlist/ --unwind 1000

cbmc_verify:
	cbmc ./tests/test_sim2.c ${LINKEDLIST_SRCS} -I ./dependencies/linkedlist/ --cvc4 --trace

build_wasm:
	docker run --rm -v $(shell pwd):/src emscripten/emsdk emcc ${LOGIC_SRCS} ${LINKEDLIST_SRCS} -I ${INCLUDES} tests/test_track.c -o ./build/helloworld.js